var mongoose = require('mongoose');
var mongodbURL = 'mongodb://localhost/takeoutWeb';
var mongodbOptions = { };
var fs = require('fs');
var models_path = __dirname + '/../models/mapping';
mongoose.connect(mongodbURL, mongodbOptions, function (err, res) {
    if (err) { 
        console.log('Connection refused to ' + mongodbURL);
        console.log(err);
    } else {
        console.log('Connection successful to: ' + mongodbURL);
    }
});

fs.readdirSync(models_path).forEach(function (file) {
    require(models_path + '/' + file);
    var modelName = file.replace('Model.js', '');
    exports[modelName] = mongoose.model(modelName);
});
